﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ecommerce.Common;

namespace Ecommerce.Areas.Manager.Models
{
    public class Product
    {
        public int ProductID { get; set; }

        [Required(ErrorMessage = "Category is required")]
        [RegularExpression(@"^[0-9]+$", ErrorMessage = "Category is a number")]
        [Display(Name = "Category")]
        public int CategoryId { get; set; }

        [Required(ErrorMessage = "Product Name is required")]
        [StringLength(200, ErrorMessage = "Max length of product name is 200")]
        [Display(Name = "Product Name")]
        public string ProdName { get; set; }

        [Required(ErrorMessage = "Price is required")]
        [Range(0, 1000, ErrorMessage = "Price larger than 0 and less than 1000")]
        [Display(Name = "Price")]
        public decimal Price { get; set; }

        [Required(ErrorMessage = "Description is required")]
        [StringLength(1000, ErrorMessage = "Max length of description is 1000")]
        [Display(Name = "Description")]
        public string Description { get; set; }

        public string Image { get; set; }

        [DisplayFormat(DataFormatString = "{0:hh\\:mm dd/MM/yy}")]
        public DateTime? LastUpdate { get; set; }

        [Required(ErrorMessage = "Status of product is required")]
        [EnumDataType(typeof(EcommerceEnum.ProductStatus), ErrorMessage = "Status of product is not right")]
        [Display(Name = "Product Status")]
        public int ProductStatus { get; set; }

        [NotMapped]
        public virtual List<Category> CategoryList { get; set; }

        [NotMapped]
        public virtual string StatusName { get; set; }

        [NotMapped]
        public virtual string ImgThum { get; set; }

        [ForeignKey("CategoryId")]
        public virtual Category Category { get; set; }
    }
}